package com.zhs.smartmall.member.service.impl;


import com.zhs.smartmall.member.model.UmsMemberCollectSubject;
import com.zhs.smartmall.member.dao.UmsMemberCollectSubjectDao;
import com.zhs.smartmall.member.service.IUmsMemberCollectSubjectService;
import com.zhs.smartmall.member.dto.UmsMemberCollectSubjectDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class UmsMemberCollectSubjectServiceImpl extends ServiceImpl< UmsMemberCollectSubjectDao, UmsMemberCollectSubject> implements IUmsMemberCollectSubjectService {

    @Resource
    private UmsMemberCollectSubjectDao umsMemberCollectSubjectDao;

    @Override
    @Transactional
    public R addOrUpdate(UmsMemberCollectSubjectDto umsMemberCollectSubjectDto) {
        if (BeanUtil.isEmpty(umsMemberCollectSubjectDto)) throw new ServiceException("数据不能为空");
        UmsMemberCollectSubject umsMemberCollectSubject = new UmsMemberCollectSubject();
        BeanUtil.copyProperties(umsMemberCollectSubjectDto,umsMemberCollectSubject);
        if (umsMemberCollectSubjectDto.getId() == null){
            umsMemberCollectSubjectDao.insert(umsMemberCollectSubject);
            return R.ok("数据插入成功");
        }else {
            umsMemberCollectSubjectDao.updateById(umsMemberCollectSubject);
            return R.ok("数据更新成功");
        }
    }
}